import 'package:pornhub_app/components/keep_alive_wrapper.dart';
import 'package:pornhub_app/components/tab_bar_indicator/tab_indicator.dart';
import 'package:pornhub_app/utils/color.dart';
import 'package:pornhub_app/views/mine/attention/controllers/attention_page_controller.dart';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class CreatorPage extends StatefulWidget {
  const CreatorPage({super.key});

  @override
  State createState() => _CreatorPageState();
}

class _CreatorPageState extends State<CreatorPage>
    with SingleTickerProviderStateMixin {
  final tabs = [
    {'name': '我关注的', 'type': 0},
    {'name': '最新收录', 'type': 1},
    {'name': '片量最多', 'type': 2},
    {'name': '最高人气', 'type': 3},
  ];
  late TabController tabController;
  final controller =
      Get.put<AttentionPageController>(AttentionPageController());
  var activeTab = 0;

  @override
  void initState() {
    tabController = TabController(length: tabs.length, vsync: this)
      ..addListener(() {
        if (tabController.index.toDouble() == tabController.animation?.value) {
          activeTab = tabController.index;
          controller.changeActiveIdx(tabController.index);
        }
      });
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
    tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: tabs.length,
      child: Column(
        children: <Widget>[
          TabBar(
            controller: tabController,
            tabs: tabs.map((v) => Tab(text: '${v['name']}')).toList(),
            labelStyle: TextStyle(
              color: COLOR.hexColor("#eb29c6"),
              fontSize: 15.sp,
              fontWeight: FontWeight.w500,
            ),
            unselectedLabelStyle: TextStyle(
              color: COLOR.hexColor("#fff"),
              fontSize: 15.sp,
              fontWeight: FontWeight.w400,
            ),
            dividerHeight: 0,
            isScrollable: false,
            indicatorWeight: 1,
            labelPadding: EdgeInsets.zero,
            indicatorPadding: EdgeInsets.zero,
            tabAlignment: TabAlignment.fill,
            indicator: TabIndicator(
              borderSide:
                  BorderSide(width: 3.w, color: COLOR.hexColor("#eb29c6")),
              indicatorBottom: 10.w,
              indicatorWidth: 18.w,
            ),
          ),
          // Expanded(
          //   child: TabBarView(
          //     controller: tabController,
          //     children: tabs.map((v) {
          //       return KeepAliveWrapper(
          //         child: Container(
          //           alignment: Alignment.center,
          //           child: v['type'] == 0
          //               ? const StarAttenData(upType: 1)
          //               : StarListData(
          //                   type: v['type'],
          //                   upType: 1,
          //                 ),
          //         ),
          //       );
          //     }).toList(),
          //   ),
          // ),
        ],
      ),
    );
  }
}
